<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('抽奖活动列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="lottery-form">
				<div class="select-list">
					<input type="hidden" name="lotteryId" id="lotteryId" th:value="${lotteryId}"/>
					<ul>
						<li>
							联系电话：<input type="text" name="tel"/>
						</li>
						<li>
							联系人：<input type="text" name="psnName"/>
						</li>
						<li>
							中奖奖项：
							<select name="lotteryPrizeTitle" id="lotteryPrizeTitle">
								<option value="">全部</option>
								<option th:each="lotteryPrizeDTO : ${lotteryPrizeDTOS}" th:text="${lotteryPrizeDTO.lotteryPrizeTitle + '（' + lotteryPrizeDTO.lotteryPrizeName + '）'}" th:value="${lotteryPrizeDTO.lotteryPrizeTitle}"></option>
							</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" id="btnSearch"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table-lottery-log"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var removeFlag = [[${@permission.hasPermi('biz:lottery:remove')}]];
	var prefix = ctx + "biz/lotteryLog";

	$(function() {
		var options = {
			id: "bootstrap-table-lottery-log",
			url: prefix + "/list",
			createUrl: prefix + "/add",
			updateUrl: prefix + "/edit/{id}",
			removeUrl: prefix + "/remove",
			exportUrl: prefix + "/export",
			showSearch: false,
			showRefresh: false,
			showToggle: false,
			showColumns: false,
			sortName: "crteTime",
			sortOrder: "desc",
			modalName: "抽奖",
			columns: [
				/*{
                    field: 'lotteryId',
                    title: '抽奖活动ID'
                },*/
				{
					field: 'tel',
					title: '抽奖人联系电话',
					sortable: true
				},
				{
					field: 'psnName',
					title: '抽奖人姓名',
					sortable: true
				},
				{
					field: 'crteTime',
					title: '抽奖时间',
					sortable: true
				},
				{
					field: 'lotteryResultId',
					title: '是否中奖',
					sortable: true,
					formatter: function(value, row, index) {
						if (value) {
							return '<span style="color: red;">是</span>'
						} else {
							return '<span>否</span>'
						}
					}
				},
				{
					field: 'lotteryPrizeTitle',
					title: '中奖奖项名称',
					sortable: true
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeLog(\'' + row.lotteryLogId +  '\'\,\'' + row.lotteryResultId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});
	function removeLog(lotteryLogId, lotteryResultId) {
		var msg = "确定删除该条抽奖记录信息吗？";
		if (lotteryResultId) {
			msg = "本条抽奖记录信息已经中奖，删除后抽奖结果将作废，确认删除？";
		}
		$.modal.confirm(msg, function() {
			var config = {
				url: "/biz/lotteryLog/remove",
				type: "post",
				dataType: "json",
				data: { "ids": lotteryLogId },
				beforeSend: function () {
					$.modal.loading("正在处理中，请稍候...");
				},
				success: function(result) {
					$.modal.closeLoading();
					if (result.code == 0) {
						$.modal.msgSuccess(result.msg);
					} else {
						$.modal.alertError(result.msg);
					}
					$("#btnSearch").click();
				}
			};
			$.ajax(config)
		});
	}
</script>
</body>
</html>